import { Logs } from '../logs/logs.entity'
import { Menus } from '../menus/menus.entity'
import { Roles } from '../roles/roles.entity'
import { User } from '../user/user.entity'

type EntityConstructor = typeof User | typeof Logs | typeof Roles | typeof Menus | 'Auth'
// 通过路径获取实体
export const getEntities = (path: string): EntityConstructor | undefined => {
  // Record 主要用于创建键值对映射，并提供类型安全
  const map: Record<string, EntityConstructor> = {
    '/users': User,
    '/logs': Logs,
    '/roles': Roles,
    '/menus': Menus,
    '/auth': 'Auth'
  }
  for (let i = 0; i < Object.keys(map).length; i++) {
    const key = Object.keys(map)[i]
    if (path.startsWith(key)) {
      return map[key]
    }
  }
}
